package com.cwf.metadatamanage.controller;

import com.cwf.metadatamanage.consts.Constants;
import com.cwf.metadatamanage.model.vo.ResultResponse;
import com.cwf.metadatamanage.model.vo.req.MetadataCollectReq;
import com.cwf.metadatamanage.service.MetadataCollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@Api(value = "/元数据采集", tags = "元数据采集", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ApiResponses(@ApiResponse(code = 404, message = "metadata collect not found"))
@RestController
@RequestMapping(value = Constants.BASE_API_PATH + "/metedataCollect", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class MetadataCollectController extends BaseController {


    @Autowired
    private MetadataCollectService metadataCollectService;

    /**
     * 元数据采集
     *
     * @param metadataCollectReq
     * @param bindingResult
     * @param request
     * @return
     */
    @ApiOperation(value = "元数据采集")
    @GetMapping("/metadataCollectBySource")
    public ResponseEntity metadataCollectBySource(@Valid @RequestBody MetadataCollectReq metadataCollectReq,
                                                  BindingResult bindingResult,
                                                  HttpServletRequest request) {
        boolean successFlag = this.metadataCollectService.metadataCollectBySource(metadataCollectReq);
        if (successFlag) {
            return ResponseEntity.ok(new ResultResponse().success());
        } else {
            return ResponseEntity.ok(new ResultResponse().fail());
        }
    }
}
